#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef char datatype;
char d[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
typedef struct Stack
{
	datatype* arr;
	int capacity;
	int size;
}Stack;
void pushstack(Stack* s,int x)
{
	if (s->capacity == s->size)
	{
		s->capacity = s->size == 0 ? 4 : 2 * s->capacity;
		s->arr = (datatype*)realloc(s->arr, sizeof(datatype) * s->capacity);
	}
	s->arr[s->size] = d[x];
	s->size++;
}
void popstack(Stack* s)
{
	if (s->size)
	{
		s->size--;
		printf("%c", s->arr[s->size]);
	}
}
int main()
{
	int a = 0;
	int x = 0;
	int z = 0;
	Stack s;
	s.arr = NULL;
	s.capacity = 0;
	s.size = 0;
	scanf("%d %d", &a,&x);
	do
	{
		pushstack(&s, a % x);
		z = a / x;
		a = z;
	} while (z);
	while (s.size>0)
	{
		popstack(&s);
	}
	free(s.arr);
}